package com.parkinglot.controller;

import com.alibaba.fastjson.JSONObject;
import com.parkinglot.util.AESUtils;
import com.parkinglot.util.HexDump;
import com.parkinglot.util.HttpUrlutils;
import com.parkinglot.util.IpUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("sanxiapay")
@RestController
public class SanXiaPayController {


    private static final  String partner="1201199597";//商户号
    private static  final String cash_register="5590";
    private static final String openiid="6750";
    private static  final String url="http://222.178.75.14:8082/emallapp/order/custPaymentApi.do?";
    private static final String url1="https://www.sanxiapay.com/emallapp/order/custPaymentApi.do?";
    @Resource
    private AESUtils aesUtils;

    @PostMapping("sanxiapay")
    @ApiOperation(value = "三峡支付")
    public String sanxiapay(HttpServletRequest request, HttpServletResponse response){
       String ipaddress=IpUtil.getIpAddress(request);
        Map<String,Object>map=new HashMap<>();
        map.put("partner","1201199597");
        Map<String,Object>orderInfo=new HashMap<>();
        orderInfo.put("out_trade_no","12313728937192379");
        orderInfo.put("subject","停车场收费");
        orderInfo.put("total_fee",1.00);
        orderInfo.put("fee_type","1");
        orderInfo.put("spbill_create_ip","123.12.12.123");
        orderInfo.put("notify_url","http://www.weixin.qq.com/wxpay/pay.php");
        orderInfo.put("return_url","http://www.weixin.qq.com/wxpay/pay.php");
        orderInfo.put("trade_channel","WECHAT");
        orderInfo.put("trade_type","JSAPI");
        orderInfo.put("is_refund","1");
        orderInfo.put("openid",openiid);
        map.put("orderInfo",orderInfo);
        String encode=AESUtils.encode("sdfsdfsdfdsf",map.get("orderInfo").toString());
        String val=HexDump.strTo16(encode);
        System.out.println(val);
        String csurl=url+"payment="+map.toString();
        System.out.println(csurl);
        HttpUrlutils httpUrlutils=new HttpUrlutils();
        Map<String,Object>result=httpUrlutils.getresultty(csurl);



        return "";
    }

    public static void main(String[] args) {
        //String ipaddress=IpUtil.getIpAddress(request);
        Map<String,Object>map=new HashMap<>();
        map.put("partner","1201199597");
        Map<String,Object>orderInfo=new HashMap<>();
        orderInfo.put("out_trade_no","12313728937192379");
        orderInfo.put("subject","停车场收费");
        orderInfo.put("total_fee",1.00);
        orderInfo.put("fee_type","1");
        orderInfo.put("spbill_create_ip","123.12.12.123");
        orderInfo.put("notify_url","http://www.weixin.qq.com/wxpay/pay.php");
        orderInfo.put("return_url","http://www.weixin.qq.com/wxpay/pay.php");
        orderInfo.put("trade_channel","WECHAT");
        orderInfo.put("trade_type","JSAPI");
        orderInfo.put("is_refund","1");
        orderInfo.put("openid",openiid);
        map.put("orderInfo",orderInfo);
        String encode=AESUtils.encode("uBdUx82vPHkDKb284d7NkjFoNcKWBuka",map.get("orderInfo").toString());
        String val=HexDump.strTo16(encode);
        map.put("orderInfo",val);
        System.out.println(map.toString());
        String csurl=url1+"payment="+ JSONObject.toJSONString(map);
        System.out.println(csurl);
        HttpUrlutils httpUrlutils=new HttpUrlutils();
        Map<String,Object>result=httpUrlutils.getresultty(csurl);
    }

}
